
const map = Object.assign({}, 
  require('./otc'), 
);
function send(res,data){
	res.setHeader("Access-Control-Allow-Origin", "*");
	res.setHeader("Access-Control-Allow-Headers", "Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild");
	res.setHeader("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
	res.setHeader("X-Powered-By","3.2.1");
	res.setHeader("Content-Type", "application/json;charset=utf-8");

	res.writeHead(200, {'Content-Type': 'application/json;charset=utf-8'});
	res.end(JSON.stringify(data));
}

const http = require('http');
const url = require("url");
http.createServer((req,res)=>{
    var parms = url.parse(req.url,true);// path query 
	var success = { "code": "", "data": {}, "msg": "", "success": true }
	var data  = map[parms.pathname]|| success || {url:req.url};
	send(res,data);	
    /*
	if(req.method =='GET'){
		send(res,{url:req.url});	
	}else{
		let postData = []
		req.on('data', chunk => { postData.push(chunk); });
		req.on('end', () => { console.log(JSON.parse(data));});  
		send(res,{url:req.url});	
	}
	*/
}).listen(9000, '127.0.0.1', () => {
    console.log(`Server is running.... /`);
	console.log(`test url is  http://127.0.0.1:9000/main/`);
});
